package com.hyny.framework.platform.system.base;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Collections;
import java.util.List;


@AllArgsConstructor
@Data
@ApiModel(value = "分页查询结果")
public class PageBean<T> implements IPage<T> {
    private static final long serialVersionUID = 8545996863226528798L;
    /**
     * 总数
     */
    @ApiModelProperty(value = "总数", position = 1)
    protected long total = 0;
    /**
     * 每页显示条数，默认 10
     */
    @ApiModelProperty(value = "每页显示条数，默认 10", position = 2)
    protected long size = 10;
    /**
     * 当前页
     */
    @ApiModelProperty(value = "当前页", position = 3)
    protected long current = 1;


    /**
     * 查询数据列表
     */
    @ApiModelProperty(value = "查询数据列表", position = 4)
    protected List<T> records = Collections.emptyList();

    @Override
    public List<OrderItem> orders() {
        return null;
    }

    @Override
    public List<T> getRecords() {
        return this.records;
    }

    @Override
    public IPage<T> setRecords(List<T> records) {
        this.records = records;
        return this;
    }

    @Override
    public long getTotal() {
        return this.total;
    }

    @Override
    public IPage<T> setTotal(long total) {
        this.total = total;
        return this;
    }

    @Override
    public long getSize() {
        return this.size;
    }

    @Override
    public IPage<T> setSize(long size) {
        this.size = size;
        return this;
    }

    @Override
    public long getCurrent() {
        return this.current;
    }

    @Override
    public IPage<T> setCurrent(long current) {
        this.current = current;
        return this;
    }


    public static PageBean copyProperties(IPage page) {
        return BeanUtil.copyProperties(page, PageBean.class);
    }
}
